package com.learn.annotation_config.component;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

/**
 * basePackages：用于指定要扫描的包路径。如果不指定默认扫描与配置类所在的包及其子包
 * includeFilters：用于指定只扫描带有特定注解的类。当指定扫描@Component时，其衍生注解@Repository、@Service、@Controller也会被扫描到
 * excludeFilters：用于排除带有特定注解的类
 */
@ComponentScan(
        basePackages = {"com.learn.annotation_config.component.beans"},
        includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = Component.class)},
        excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class})}
)
public class ComponentApplication {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ComponentApplication.class);
        System.out.println(applicationContext.getBean("userDao"));
        System.out.println(applicationContext.getBean("userServiceImpl"));
    }
}
